import '../public.dart';

class GiftcardApi {
  /// 分页查询卡种类
  /// /giftCard/typePage
  static Future<BaseResponse<PagedDataResponse<SysGiftCardTypeEntity>>>
  typePage(GiftCardTypePageRequestDto params) async {
    final response = await HttpUtil().request(
      '/giftCard/typePage',
      method: 'POST',
      data: params.toJson(),
    );
    return BaseResponse<PagedDataResponse<SysGiftCardTypeEntity>>.fromJson(
      response,
      fromJsonT: (j) => PagedDataResponse<SysGiftCardTypeEntity>.fromJson(
        j,
        (j2) => SysGiftCardTypeEntity.fromJson(j2),
      ),
    );
  }

  /// 分页查询卡分类
  /// /giftCard/categoryPage
  static Future<
    BaseResponse<PagedDataResponse<GiftCardCategoryPageResponseDto>>
  >
  categoryPage(GiftCardCategoryPageRequestDto params) async {
    final response = await HttpUtil().request(
      '/giftCard/categoryPage',
      method: 'POST',
      data: params.toJson(),
    );
    return BaseResponse<
      PagedDataResponse<GiftCardCategoryPageResponseDto>
    >.fromJson(
      response,
      fromJsonT: (j) =>
          PagedDataResponse<GiftCardCategoryPageResponseDto>.fromJson(
            j,
            (j2) => GiftCardCategoryPageResponseDto.fromJson(j2),
          ),
    );
  }

  /// 卡种类列表
  /// /giftCard/typetList
  static Future<BaseResponse<List<SysGiftCardTypeEntity>>> typetList_1() async {
    final response = await HttpUtil().request(
      '/giftCard/typetList',
      method: 'GET',
    );
    return BaseResponse<List<SysGiftCardTypeEntity>>.fromJson(
      response,
      fromJsonT: (j) =>
          (j as List).map((e) => SysGiftCardTypeEntity.fromJson(e)).toList(),
    );
  }

  /// 取指定卡种下的卡分类列表
  /// /quote/categoryList/{typeId}
  /// 接口说明
  /// 手机用户卖卡选择卡分类时，调用此接口
  static Future<BaseResponse<List<SysGiftCardCategoryEntity>>>
  categoryListByType_2(int typeId) async {
    final response = await HttpUtil().request(
      '/quote/categoryList/$typeId',
      method: 'GET',
    );
    return BaseResponse<List<SysGiftCardCategoryEntity>>.fromJson(
      response,
      fromJsonT: (j) => (j as List)
          .map((e) => SysGiftCardCategoryEntity.fromJson(e))
          .toList(),
    );
  }
}
